<template>
  <div class="tabbar_item" @click="Goto()">
    <div v-if="!isActive"><slot name="img_icon"></slot></div>
    <div v-else><slot name="img_active_icon"></slot></div>
    <div :style="activeColor"><slot name="text_icon"></slot></div>
  </div>
</template>

<script>
export default {
  name: "TabbarItem",
  props: {
    link: String,
    aColor: {
      type: String,
      default: "red"
    }
  },
  methods: {
    Goto(){
      this.$router.replace(this.link).catch(err=>err);
    }
  },
  computed: {
    isActive(){
      return this.$route.path.indexOf(this.link) !== -1
    },
    activeColor(){
      return this.isActive?{color:this.aColor}:{}
    }
  }
}
</script>

<style>
  .tabbar_item{
    flex:1;
    text-align: center;
    height: 49px;
    font-size: 14px;
    background-color: #fff;
  }

  .tabbar_item img{
    width: 24px;
    margin-top: 5px;
    vertical-align: middle;
    margin-bottom: 2px
  }
</style>